package demo1;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;

public class Demo2 {
    public static void findMax(Map<String, Integer> map) {
        PriorityQueue<Map.Entry<String, Integer>> queue = new PriorityQueue<>(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o2.getValue() - o1.getValue();
            }
        });
        for(Map.Entry<String, Integer> entry : map.entrySet()) {
            queue.add(entry);
        }
        while(queue.size() > 2) {
            System.out.println(queue.poll().getKey());
        }
    }
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("John", 35);
        map.put("Bob", 40);
        map.put("Alice", 30);
        map.put("Tom", 45);
        map.put("Jerry", 50);

        findMax(map);


    }
}
